package com.adpter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.ocean.util.common.StringUtil;
import com.matang.R;
import com.modle.SkillStruct;

public class SkillChooseAdapter extends BaseAdapter {
	ArrayList<SkillStruct> dataList;
	Context context;
	LayoutInflater inflater;

	public SkillChooseAdapter(ArrayList<SkillStruct> dataList, Context context) {
		super();
		this.context = context;
		this.dataList = dataList;
		this.inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return dataList.size();
	}

	@Override
	public Object getItem(int position) {
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		ViewHolder vh = null;
		if (view == null) {
			view = LayoutInflater.from(context).inflate(
					R.layout.list_item_skill, null);
			vh = new ViewHolder();
			vh.nameTv = (TextView) view.findViewById(R.id.name_tv);
			vh.jtIv = (ImageView) view.findViewById(R.id.jt_iv);
			view.setTag(vh);
		} else {
			vh = (ViewHolder) view.getTag();

		}
		if (StringUtil.isListNull(dataList.get(position).childList)) {
			vh.jtIv.setVisibility(View.GONE);

		} else {
			vh.jtIv.setVisibility(View.VISIBLE);
		}
		vh.nameTv.setText(dataList.get(position).name);

		return view;
	}

	class ViewHolder {
		TextView nameTv;
		ImageView jtIv;

	}
}